package com.wofish.web.controller.member;

import com.wofish.common.annotation.Log;
import com.wofish.common.core.controller.BaseController;
import com.wofish.common.core.domain.AjaxResult;
import com.wofish.common.core.page.TableDataInfo;
import com.wofish.common.enums.BusinessType;
import com.wofish.common.utils.poi.ExcelUtil;
import com.wofish.member.domain.MemberAccount;
import com.wofish.member.service.IMemberAccountService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 会员登录账号 信息操作处理
 * 
 * @author wofish
 * @date 2019-04-21
 */
@Controller
@RequestMapping("/member/memberAccount")
public class MemberAccountController extends BaseController {
    private String prefix = "member/memberAccount";
	
	@Autowired
	private IMemberAccountService memberAccountService;
	
	@RequiresPermissions("member:memberAccount:view")
	@GetMapping()
	public String memberAccount() {
	    return prefix + "/memberAccount";
	}
	
	/**
	 * 查询会员登录账号列表
	 */
	@RequiresPermissions("member:memberAccount:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MemberAccount memberAccount) {
		startPage();
        List<MemberAccount> list = memberAccountService.selectMemberAccountList(memberAccount);
		return getDataTable(list);
	}
	



	/**
	 * 导出会员登录账号列表
	 */
	@RequiresPermissions("member:memberAccount:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberAccount memberAccount) {
    	List<MemberAccount> list = memberAccountService.selectMemberAccountList(memberAccount);
        ExcelUtil<MemberAccount> util = new ExcelUtil<MemberAccount>(MemberAccount.class);
        return util.exportExcel(list, "memberAccount");
    }
	
	/**
	 * 新增会员登录账号
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存会员登录账号
	 */
	@RequiresPermissions("member:memberAccount:add")
	@Log(title = "会员登录账号", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(MemberAccount memberAccount) {
		return toAjax(memberAccountService.insertMemberAccount(memberAccount));
	}

	/**
	 * 修改会员登录账号
	 */
	@GetMapping("/edit/{memberId}")
	public String edit(@PathVariable("memberId") Long memberId, ModelMap mmap) {
		MemberAccount memberAccount = memberAccountService.selectMemberAccountById(memberId);
		mmap.put("memberAccount", memberAccount);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存会员登录账号
	 */
	@RequiresPermissions("member:memberAccount:edit")
	@Log(title = "会员登录账号", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MemberAccount memberAccount) {
		return toAjax(memberAccountService.updateMemberAccount(memberAccount));
	}
	
	/**
	 * 删除会员登录账号
	 */
	@RequiresPermissions("member:memberAccount:remove")
	@Log(title = "会员登录账号", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(memberAccountService.deleteMemberAccountByIds(ids));
	}
	
}
